package hacker_rank.oct13;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Arrays;

public class AngryChildren2 {
	public static void main(String[] args) throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

		int N = Integer.parseInt(br.readLine());
		int K = Integer.parseInt(br.readLine());

		long[] ar = new long[N];
		for (int i = 0; i < N; i++) {
			ar[i] = Long.parseLong(br.readLine());
		}

		solve(ar, N, K);

	}

	private static void solve(long[] ar, int n, int k) {
		Arrays.sort(ar);

		long D = 0;
		long sum = 0;
		long res = 0;

		for (int i = 1; i < k; i++)
			sum += ar[i];

		System.out.println("Sum: " + sum);
		for (int i = 0; i < k - 1; i++) {
			for (int j = i + 1; j < k; j++) {
				D += Math.abs(ar[i] - ar[j]);
			}
		}

		res = D;

		for (int i = 1; i <= n - k; i++) {
		}

		System.out.println(res);

		System.out.println(Arrays.toString(ar));

	}
}